<?php

/*
 * Corresondiente al controller de Departamento
 */
class m_departamento extends CI_Model{
    
    var $table='sc_dpto';
    var $id_table='dpto_id';
    public function __construct() {
        parent::__construct();
    
        $table='sc_dpto';
        $id_table='dpto_id';
        
    }
    
    /**
     * Retorna todo el 
     * @return type
     */
    public function getAll()
    {
        $query= $this->db->get($this->table);
        return $query->result();
    }
    
    
    /**
     * Return functions 
     * 
     * @param type $limit
     * @param type $start
     * @return type
     */
    public function getList($limit,$start)
    {
        $this->db->limit($limit,$start);
        $query=$this->db->get($this->table); 
        return $query->result();
    }
    


    public function getById($dpto_id)
    {
         $this->db->where($this->id_table,$dpto_id);  
         $query=$this->db->get($this->table);
         return $query->result();

    }
    
    
    /**
     * Cantidad de Rows
     * @return type
     */
    public function getRowCount()
    {
       $query= $this->db->get($this->table);
       return $query->num_rows();
       
    }
    
    
    /**
     * Insert data 
     * @param type $data
     */
    public function add($data)
    {
        $this->db->insert($this->table,$data);
    }
    
    /**
     * Delete department
     * @param type $id
     */
    public function delete($id)
    {
        $this->db->where($this->id_table,$id);
        $this->db->delete($this->table);
    }
   
    /**
     * Get last row inserted
     * @return type
     */
    public function getRowLastInsert()
    {
        //get last id
        $last_id=$this->getIdLastInsert();
        //select row last insert
        $this->db->where($this->id_table,$last_id);
        $query=$this->db->get($this->table);
        return $query->result();        
    }


    /**
     * Get last insert id
     * @return type
     */
    public function getIdLastInsert()
    {
        return $this->db->insert_id();
    }
    
   /**
    * Update Table
    * @param type $id
    * @param type $data
    */    
 
    public function update($id,$data)
    {
        $this->db->where($this->id_table,$id);
        $this->db->update($this->table,$data);
        
    }
    
       
       
}

?>
